package com.bicon.botu.mall.member.rpc;


import com.bicon.botu.core.base.common.BusinessException;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.member.dto.DefaultAddressDto;
import com.bicon.botu.mall.member.entity.Address;
import com.bicon.botu.mall.member.service.IAddressService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地址rpc
 *
 * @author lishuangxi
 * @date 2017/9/8 0008 下午 16:05
 */
@RestController
@RequestMapping("/V3.0.0/rpc/address")
public class AddressRpc extends BaseController {


    @Autowired
    private IAddressService iAddressService;

    /**
     * 根据id查询地址
     *
     * @param addressIds 多个地址id
     * @return
     */
    @RequestMapping(value = "/selectAddress", method = RequestMethod.POST)
    public List<Address> getProductList(@RequestParam(value = "addressIds") String[] addressIds) {
        if (StringUtils.isEmpty(addressIds.toString())){
            throw new BusinessException("地址不能空");
        }
        List<Address> addressList =  iAddressService.selectAddress(addressIds);
        return addressList;
    }

    /**
     * 查询用户默认地址
     *
     *
     * @param userId 用户Id
     * @return
     */
    @RequestMapping(value = "/default", method = RequestMethod.POST)
    public DefaultAddressDto getDefault(@RequestParam(value = "userId") String userId) {
        if (StringUtils.isEmpty(userId)){
            throw new BusinessException("用户不能为空");
        }
        DefaultAddressDto defaultAddressDto = iAddressService.selectDefaultAddress(userId);
        return defaultAddressDto;
    }
}
